<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增岗位')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-post-add" th:object="${post}">
			<input id="id" name="id" type="hidden" th:field="*{id}"/>
			<input id="id" name="deptId" type="hidden" th:field="*{deptId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">库存物料编码：</label>
				<div class="col-sm-8">
					<input class="form-control"  type="text" readonly name="inventoryCode" id="inventoryCode" th:field="*{inventoryCode}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">库存物料名称：</label>
				<div class="col-sm-8">
					<input class="form-control"  type="text" readonly name="inventoryName" id="inventoryName" th:field="*{inventoryName}"  required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">现有库存数量：</label>
				<div class="col-sm-8">
					<input class="form-control"  type="text" readonly name="xykcsl" id="xykcsl"  th:value="*{inventoryNumber}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">入库物料数量：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="cksl" id="cksl" required>
					<input class="form-control" type="hidden" name="adjustId" id="adjustId" value="1" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">入库后库存数量：</label>
				<div class="col-sm-8">
					<input class="form-control"  readonly type="text" name="inventoryNumber" id="inventoryNumber" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">入库原因：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control"></textarea>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "system/kcgl";

		document.getElementById('cksl').addEventListener('keyup', function() {
			var cksl = this.value;
			var istrue = isEmpty(cksl);


			var isnumber = isNumber(parseInt(this.value));

			if(isnumber == false){
				alert('调整数量必须是数字');
				document.getElementById('cksl').value='';
				document.getElementById('inventoryNumber').value='';
				return false;
			}

			if(istrue==true){
				document.getElementById('inventoryNumber').value='';
				return false;
			}

			var xykcsl = document.getElementById('xykcsl').value;

			let xy = parseInt(xykcsl);
			let rk = parseInt(this.value);

			var tzkc = xy+rk;
			if(tzkc<0){
				alert("调整后库存不可小于0");
				document.getElementById('cksl').value='';
				document.getElementById('inventoryNumber').value='';
				return false;
			}

			$('#inventoryNumber').val(xy+rk);
			document.getElementById('inventoryNumber').value=xy+rk;
		});

		function isEmpty(data) {
			if (typeof data === "undefined" || data === null) {
				return true;
			}
			if (typeof data === "string" && data.trim() === "") {
				return true;
			}
			if (Array.isArray(data) && data.length === 0) {
				return true;
			}
			if (typeof data === "object" && Object.keys(data).length === 0) {
				return true;
			}
			return false;
		}


		function isNumber(value) {
			return typeof value === 'number' && !isNaN(value);
		}


		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/ckrk", $('#form-post-add').serialize());
	        }
	    }
	</script>
</body>
</html>
